//右滑关闭
mui.init({
	swipeBack: true,
})
var fs = true;
var UserNO = localStorage.getItem("UserName");
mui.plusReady(function() {
	var currentwindow = plus.webview.currentWebview();
	if (currentwindow.WorkOrderNO != '' && currentwindow.WorkOrderNO != undefined) {
		$("#WorkOrderNO").val(currentwindow.WorkOrderNO);
		$("#MatNO").val(currentwindow.MaterialNO);
		$("#MaterialName").val(currentwindow.MaterialName);
	} else {
		mui.toast("未带入参数。", {
			duration: '1000',
			type: 'div'
		});
	}
	//下线条码扫描
	$("#OutBar").keyup(function(e) {
		if (e.keyCode == 13) {
			var OutBarCodeNO = $("#OutBar").val();

			var workorderNO = $("#WorkOrderNO").val();
			if (OutBarCodeNO === null || OutBarCodeNO === undefined) {
				mui.toast("请扫描条码。", {
					duration: '1000',
					type: 'div'
				});
				OutBarCodeNO.focus();
			}
			xccpostAsync("JyhstWebASHX.ashx", {
				Action: "WOReturnMaterialBarcode",

				workorderNO: workorderNO,
				OutBarCodeNO: OutBarCodeNO,
				UserNO: UserNO
			}, function(data) {
				console.log(JSON.stringify(data));

				if (data.Code == "200") {

					$("#txtResult").val("条码" + InBarCodeNO + "下线成功!");

				} else {
					$("#txtResult").val("条码下线失败:" + data.Message);

				}
				$("#OutBar").val('');
				$("#OutBar").focus();
				plus.nativeUI.closeWaiting();
			}, function(error) {
				console.log("没有数据....");
				$("#OutBar").val('');
				$("#OutBar").focus();
				plus.nativeUI.closeWaiting();
			});


		}

	});
	//关闭等待框
	plus.nativeUI.closeWaiting();
	//显示当前页面
	//mui.currentWebview.show();
});


//一键下料模式
function showinfo() {
	var indexs = $("#OrderIndex").val();
	var workorderNO = $("#WorkOrderNO").val();
	console.log(indexs);

	var indexText = $("#OrderIndex option:selected").text();
	// console.log(indexs);
	if (indexs == 0) {
		mui.toast("请选择下料模式。", {
			duration: '1000',
			type: 'div'
		});
		return;
	}
	mui.confirm("请确认是否一键下料.", "下料提示", ['确认', '取消'], function(e) {
		if (e.index == 0) {
			xccpostAsync("JyhstWebASHX.ashx", {
				Action: "UpdateAll",
				workorderNO: workorderNO,
				indexs: indexs,
				UserNO: UserNO
			}, function(data) {
				console.log(JSON.stringify(data));
				if (data.Code == "200") {
					$("#txtResult").val(indexText + "下线成功!");
					mui.toast(indexText + "下线成功!", {
						duration: '1000',
						type: 'div'
					});

				} else {
					$("#txtResult").val("条码下线失败:" + data.Message);
					mui.toast(indexText + "下线失败!", {
						duration: '1000',
						type: 'div'
					});
					Audios();
				}
				$("#OutBar").val('');
				$("#OutBar").focus();
				plus.nativeUI.closeWaiting();
			}, function(error) {
				console.log("没有数据....");
				mui.toast("下线失败!", {
					duration: '1000',
					type: 'div'
				});
				$("#OutBar").val('');
				$("#OutBar").focus();
				plus.nativeUI.closeWaiting();
			});

		} else {
			$("#OutBar").val('');
			$("#OutBar").focus();
		}

	})

}

//失败报警
function Audios() {
	var audio = new Audio('../../../fonts/baojin.mp3');

	audio.play();
}